You attempted to establish referential integrity on a Relation object of a QueryDef object, which is not supported.
Change the Attributes property setting of the Relation object to dbRelationDontEnforce.